﻿<!DOCTYPE html>
<html lang="en">
	<head>
		<title>JavaScript加减运算</title>
	</head>
	<body>
		<script>
			var a = 287;
			var b = 102;
			function BinaryAdd(a,b) {  
				do {  
					var add = a ^ b;          
					var carry = (a & b) << 1;
					a = add;  
					b = carry;  
				} while (carry != 0);    
				return add;  
			}
			function BinarySub(a,b) {  
				return BinaryAdd(a, BinaryAdd(~b, 1));  
			} 
			console.log("a+b的结果为："+BinaryAdd(a,b));
			console.log("a-b的结果为："+BinarySub(a,b));
		</script>
	</body>
</html>

